package com.zggk.lzz.xcbgadd;

import android.app.Activity;

import com.alibaba.fastjson.JSON;
import com.zggk.lzz.api.MyApplication;
import com.zggk.lzz.api.Urls;
import com.zggk.lzz.callback.StringDialogCallback;
import com.zggk.lzz.mvp.BasePresenterImpl;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

/**
 * MVPPlugin
 *  邮箱 784787081@qq.com
 */

public class XcbgAddPresenter extends BasePresenterImpl<XcbgAddContract.View> implements XcbgAddContract.Presenter{
    @Override
    public void getData(Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/rhms/lzzapp/patrolEnd")
                .params("userId", MyApplication.spUtils.getString("UserID"))
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        XcbgAddBean xcbgAddBean = JSON.parseObject(response.body(),XcbgAddBean.class);
                        if (mView == null)
                            return;
                        if (xcbgAddBean.getCode().equals("200")){
                            mView.getDatas(xcbgAddBean.getData());
                        }else {
                            mView.onRequestError(xcbgAddBean.getMessage());
                        }
                    }
                });
    }
    @Override
    public void addData(String remark,String roadStr,Activity activity) {
        OkGo.<String>post(Urls.JAVASERVER+"pms/rhms/lzzapp/patrolSubmit")
                .params("userId", MyApplication.spUtils.getString("UserID"))
                .params("remark", remark)
                .params("xcfw", roadStr)
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .execute(new StringDialogCallback(activity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        XcbgAddBean xcbgAddBean = JSON.parseObject(response.body(),XcbgAddBean.class);
                        if (mView == null)
                            return;
                        if (xcbgAddBean.getCode().equals("200")){
                            mView.addDatas();
                        }else {
                            mView.onRequestError(xcbgAddBean.getMessage());
                        }
                    }
                });
    }
    @Override
    public void addRoad() {
        OkGo.<String>post(Urls.JAVASERVER+"pms/rhms/lzzapp/getXCFW")
                .params("userId", MyApplication.spUtils.getString("UserID"))
                .params("token", "Bearer$" + MyApplication.spUtils.getString("Token",""))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        XcbgRoadBean xcbgRoadBean = JSON.parseObject(response.body(),XcbgRoadBean.class);
                        if (mView == null)
                            return;
                        if (xcbgRoadBean.getCode().equals("200")){
                            mView.addRoads(xcbgRoadBean);
                        }else {
                            mView.onRequestError(xcbgRoadBean.getMessage());
                        }
                    }
                });
    }
}
